﻿@{
    ViewBag.Title = "修改密码";
    Layout = "~/Views/Shared/_LayuiLayout.cshtml";
}
@model UserChangePwdOut
<form class="layui-form layui-form-pane">
    <input type="hidden" name="Id" value="@Model.ID" />
    <div class="layui-form-item">
        <label class="layui-form-label">原来密码</label>
        <div class="layui-input-block">
            <input type="text" name="OldPWD" required lay-verify="required" placeholder="请输入原来密码" autocomplete="off" class="layui-input" value="@Model.OldPWD">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-block">
            <input type="text" id="txtNewpwd1" name="NewPWD" required lay-verify="required" placeholder="请输入新密码" autocomplete="off" class="layui-input" value="@Model.NewPWD">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block">
            <input type="text" id="txtNewPwd2" name="NewPWD2" required lay-verify="required" placeholder="请输入新密码" autocomplete="off" class="layui-input" value="@Model.NewPWD2">
        </div>
    </div>
    <div class="title" style="line-height:30px;">&nbsp; 1、密码中必须包含字母、数字，至少8个字符，最多30个字符。</div>
    <div class="title" style="line-height:30px;">&nbsp; 2、新用户登录系统，必须强制更改密码。</div>
    <div class="fixed-block">
        <div class="btn-list">
            <button type="button" class="layui-btn" lay-submit="" lay-filter="Save">修改密码</button>
        </div>
    </div>
</form>



@section scripts{
    <script type="text/javascript">
        var $, layer;
        layui.use(['form'], function () {
            var form = layui.form;
            $ = layui.jquery;
            layer = parent.layer === undefined ? layui.layer : parent.layer;

            var postUrl = '@Url.Action("EditPass", "User")';

            // 监听关闭
            $('#btnCancel').on('click', function () {
                layer_close();
            });

            // 监听提交
            form.on('submit(Save)', function (data) {

                var a = yanzhen();

                if (a) {
                    var b = yanzhen2();
                    if (b) {

                        var loading = layer.load();
                        $.post(postUrl, data.field,
                            function (result) {
                                layer.close(loading);
                                if (result.Success) {
                                    layer.msg(result.Message, { icon: 1, time: 6000 });
                                    parent.reload();
                                    layer_close();
                                } else {
                                    layer.alert(result.Message, { icon: 2 });
                                }
                            });
                        return false;
                    }
                }
            });

            function yanzhen() {

                var regex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z]).{6,30}');
                if (!regex.test(document.getElementById("txtNewpwd1").value)) {
                    layer.msg('密码中必须包含字母、数字，至少6个字符，最多30个字符,请重新输入',{icon:0});
                    document.getElementById("txtNewpwd1").focus();
                    return false;

                } else { return true;}
            }

            function yanzhen2() {
                if (document.getElementById("txtNewpwd1").value != document.getElementById("txtNewPwd2").value) {
                    document.getElementById("txtNewpwd1").focus();
                    layer.msg("两次密码不致，请重新输入！", {icon:0});
                    return false
                } else { return true; }
            }

        });
    </script>
}